//
//  MKUITabBarController.h
//  MKUI
//	组合了页签视图以及页签内容视图
//  Created by sushangjin on 16/3/29.
//  Copyright © 2016年 sushangjin. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "MKUITabBarContentView.h"
#import "MKUITabBarItemContainer.h"
#import "MKUITabBarContentContainer.h"
#import "MKUITabBarContentProtocol.h"

NS_ASSUME_NONNULL_BEGIN
@class MKUITabBarController;
@protocol MKUITabBarControllerDelegate <NSObject>
@optional
- (BOOL)tabBarController:(MKUITabBarController *)controller shouldSelectIndex:(NSInteger)index;//是否可以选择某一个
- (void)tabBarController:(MKUITabBarController *)controller willSelectIndex:(NSInteger)index;//即将选择某一个
- (void)tabBarController:(MKUITabBarController *)controller didSelectIndex:(NSInteger)index;//已经选择某一个
@end

@interface MKUITabBarController : NSObject
@property(nonatomic,weak,nullable) id<MKUITabBarControllerDelegate> delegate;
//页签内容数组,设置数组之后，并不会刷新UI，需手动调用reloadData
@property(nonatomic,strong,nullable) NSArray<id<MKUITabBarContentProtocol>> *contents;
//标签数组
@property(nonatomic,readonly,nullable) NSArray<__kindof UITabBarItem *> *items;

@property(nonatomic,strong,nullable) id<MKUITabBarContentProtocol> selectedContent;//选中的内容，修改它，并不会刷新UI，需手动调用reloadData
@property(nonatomic,assign) NSInteger selectedIndex;//选中项位置，修改它，并不会刷新UI，需手动调用reloadData

//标签，默认为MKUITabBarItemViewContainerCollectionView
@property(nonatomic,readonly) Class itemContainerClass;
@property(nonatomic,readonly) __kindof MKUITabBarItemContainer *itemContainer;

//页签内容，默认为MKUITabBarContentContainerListView
@property(nonatomic,readonly) Class contentContainerClass;
@property(nonatomic,readonly) __kindof MKUITabBarContentContainer *contentContainer;


- (instancetype)initWithItemContainerClass:(Class)itemContainerClass contentContainerClass:(Class)contentContainerClass NS_DESIGNATED_INITIALIZER;

- (void)reloadData;//刷新UI
//刷新UI，并显示动画效果
- (void)reloadDataWithAnimated:(BOOL)animated;

/// 切换选中项,会刷新UI
/// @param index 选中项索引
/// @param animated 是否动画
- (void)setSelectedIndex:(NSInteger)index animated:(BOOL)animated;

//是否可以选中指定项
- (BOOL)shouldSelectIndex:(NSInteger)index;

//标签选中通知
- (void)itemContainerDidSelectIndex:(NSInteger)index animated:(BOOL)animated;
//内容选中通知
- (void)contentContainerDidSelectIndex:(NSInteger)index animated:(BOOL)animated;

/// 当容器为scrollview时，scrollview滚动通知
/// @param fromIndex 滚动开始页签位置
/// @param toIndex 滚动期望结束页签位置
/// @param progress 从from到to的完成进度，取值[0,1]
- (void)contentContainerDidScrollFrom:(NSInteger)fromIndex to:(NSInteger)toIndex withProgress:(CGFloat)progress;
@end

@interface MKUITabBarController (ContentsUpdate)
//添加页签内容到最后一个位置，并不会刷新UI，需手动调用reloadData
- (void)addContent:(id<MKUITabBarContentProtocol>)content;
//添加页签内容到指定位置，并不会刷新UI，需手动调用reloadData
- (void)insertContent:(id<MKUITabBarContentProtocol>)content toIndex:(NSInteger)index;
//删除某个页签内容，并不会刷新UI，需手动调用reloadData
- (void)removeContent:(id<MKUITabBarContentProtocol>)content;
//删除某个页签内容，并不会刷新UI，需手动调用reloadData
- (void)removeContentAtIndex:(NSInteger)index;
@end
NS_ASSUME_NONNULL_END
